Interactive Data Visualization

Row

Total #rstats Tweets

12101

Total Tweeters

2382

Total Likes

123579

Total Retweets

104939

Tweets Today

517

Tweeters Today

192

Row

Daily Count of Tweets

Re-tweets vs Likes on tweets

---
title: "Rstats Dashboard"
output: 
  flexdashboard::flex_dashboard:
    orientation: rows
    vertical_layout: fill
    social: [ "twitter", "facebook", "menu"]
    source_code: embed
---

```{r setup, include=FALSE}
library(flexdashboard)
library(rtweet)
library(lubridate)
library(anytime)
library(dplyr)
library(plotly)

read_df <- read_twitter_csv("rstats_data/rstats_Tweet.csv")

creation_date <- read_df$Tweet_Date
first_part <- suppressWarnings(as_date(creation_date[!is.na(as_date(creation_date))]))
second_part <- suppressWarnings(anydate(as.numeric(creation_date[!is.na(as.numeric(creation_date))]), tz="UTC", asUTC = FALSE))
creation_date <- c(first_part, second_part)
remove(first_part, second_part)
read_df$Tweet_Date <- creation_date

total_tweets <- length(unique(read_df$Status_ID))
total_users <- length(unique(read_df$User_ID))
total_likes <- sum(read_df$Likes)
total_retweets <- sum(read_df$Retweet_Count)

daily_count_df <- as.data.frame(table(creation_date))
tweets_today <- daily_count_df$Freq[nrow(daily_count_df)]

today_df <- read_df %>%
  filter(Tweet_Date == Sys.Date()-1)
users_today <- length(unique(today_df$User_ID))

```

# Interactive Data Visualization

## Row

### Total #rstats Tweets

```{r}
valueBox(total_tweets, icon = "fa-twitter", color = "aqua")
```

### Total Tweeters

```{r}
valueBox(total_users, icon = "fa-user", color = "green")
```

### Total Likes

```{r}
valueBox(total_likes, icon = "fa-thumbs-up", color = "red")
```

### Total Retweets

```{r}
valueBox(total_retweets, icon = "fa-twitter", color = "fuchsia")
```

### Tweets Today

```{r}
valueBox(tweets_today, icon = "fa-comments", color = "purple")
```

### Tweeters Today

```{r}
valueBox(users_today, icon = "fa-users", color = "orange")
```

## Row

### Daily Count of Tweets

```{r}
plot1 <- daily_count_df %>%
  plot_ly(x = ~creation_date,
          y = ~Freq,
          color = "orange",
          type = 'bar') %>%
  layout(xaxis = list(title = "Date"), yaxis = list(title = "Number of Tweets", 
                                                    range = c(0, max(daily_count_df$Freq))))
plot1
```

### Re-tweets vs Likes on tweets

```{r}
unique_days <- unique(creation_date)
len <- 1:length(unique_days)
rtc <- lapply(len, function(x){sum(subset(read_df, Tweet_Date==unique_days[x])$Retweet_Count)})
rtc <- unlist(rtc)
lc <- lapply(len, function(x){sum(subset(read_df, Tweet_Date==unique_days[x])$Likes)})
lc <- unlist(lc)

data <- data.frame(unique_days, rtc, lc)

plot2 <- plot_ly(data, x = ~unique_days, y = ~rtc, type = 'bar', name = 'Re-Tweets',
               marker = list(color = 'rgb(55, 83, 109)')) %>%
  add_trace(y = ~lc, name = 'Likes', marker = list(color = 'rgb(26, 118, 255)')) %>% 
  layout(title = 'Count of Re-Tweets and Likes for #rstats ',
         xaxis = list(
           title = "Date",
           type = 'date',
           tickformat = "%d %B (%a)
%Y", tickfont = list( size = 14, color = 'rgb(107, 107, 107)')), yaxis = list( title = 'Frequency', range = c(0, max(max(rtc), max(lc))), titlefont = list( size = 16, color = 'rgb(107, 107, 107)'), tickfont = list( size = 14, color = 'rgb(107, 107, 107)')), legend = list(x = 0, y = 1, bgcolor = 'rgba(255, 255, 255, 0)', bordercolor = 'rgba(255, 255, 255, 0)'), barmode = 'group', bargap = 0.15, bargroupgap = 0.1) plot2 ```